1. Field of the Disclosure
The disclosure relates to a method for sharing unused memories of virtual machines and a computer system using the same.
2. Description of Related Art
As computer hardware cost decreases and demand for large-scale server increases, virtual machines gradually draw attentions. The virtual machine is an interface used between software and a computer system, which may provide various resources of the computer system to the software for utilization. The software is generally an operating system. Therefore, the operating system can access the resources of the computer system through the virtual machine. However, a plurality of virtual machines can be installed on the computer system, and each of the virtual machines may install a different operating system. For example, the Windows operating system of Microsoft and the Linux operating system can be simultaneously installed in different virtual machines on a same computer system.
On the other hand, when a new operating system is developed, the operating system of different versions can be tested on the computer system, where the operating system of different versions are respectively installed on different virtual machines, and when one of the tested operating systems has an error, none-operation of the entire computer system is avoided. Moreover, as a cloud computing is widely used, mobility of a server becomes more and more important. Since the virtual machine can loose a coupling relationship between the operating system and the computer system, one operating system can be moved to another computer system along with the virtual machine, so as to balance a load of the server.
However, although the computer system can execute a plurality of virtual machines in theory, the number of executable virtual machines is limited, and one of the reasons thereof relates to a memory capacity. The memory capacity configured on the computer system is limited, and if the memory is averagely distributed to the executed virtual machines, the memory capacity used by each virtual machine is probably insufficient. However, theses virtual machines probably use a same program code or data (for example, a kernel program of the Windows operating system), so that the same data is stored in each of the virtual machines. If the same data in the virtual machines is shared, and the virtual machines use only one copy of the program code or data stored in the memory of the computer system, the memory of the computer system can be effectively used. One of the methods for sharing the memory is to calculate a hash value of each memory page in each of the virtual machines according to a hash function, and compare whether the memory pages of the virtual machines have the same hash value. If different virtual machines have the memory pages with the same hash value, theses memory pages are probably stored with the same data, which can be further shared. However, such method has to calculate the hash value of each memory page of each of the virtual machines, which is time consuming. Therefore, how to effectively share the memories in the virtual machines is an important issue to be developed by related practitioners.